<?php

require_once 'lib/AipBase.php';

class AipTrans extends AipBase
{
    private $texttrans = 'https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1';

    private $texttrans_dict = 'https://aip.baidubce.com/rpc/2.0/mt/texttrans-with-dict/v1';

    private $doc = 'https://aip.baidubce.com/rpc/2.0/mt/v2/doc-translation/create';

    private $pic = 'https://aip.baidubce.com/file/2.0/mt/pictrans/v1';

    /**
     * 文本翻译-通用版
     * doc: https://ai.baidu.com/ai-doc/MT/4kqryjku9
     * @param string $from
     * @param string $to
     * @param string $q
     * @return bool|mix|mixed|string[]
     */
    public function texttrans(string $from, string $to, string $q)
    {
        $url = $this->texttrans;
        $formData = json_encode([
            'from' => $from,
            'to' => $to,
            'q' => $q,
        ]);
        return $this->trans($url, $formData);
    }

    /**
     * 文本翻译-词典版
     * doc: https://ai.baidu.com/ai-doc/MT/nkqrzmbpc
     * @param string $from
     * @param string $to
     * @param string $q
     * @return bool|mix|mixed|string[]
     */
    public function dicttrans(string $from, string $to, string $q)
    {
        $url = $this->texttrans_dict;
        $formData = json_encode([
            'from' => $from,
            'to' => $to,
            'q' => $q,
        ]);
        return $this->trans($url, $formData);
    }
    
    public function trans($url, $data)
    {
        return $this->request($url, $data);
    }
}